<template>
	<view class="content">
		<view class="title">任务信息</view>
		<view class="msg">
			<view class="li">任务名称<text>{{taskInfoList[0]?.taskName}}</text></view>
			<view class="li">任务类型<text>{{taskInfoList[0]?.taskType}}</text></view>
			<view class="li">所属阶段<text>{{taskInfoList[0]?.stage}}</text></view>
			<view class="li">工程量<text>{{taskInfoList[0]?.quantity}}</text></view>
			<view class="li">责任单位<text>{{taskInfoList[0]?.unitsName}}</text></view>
			<view class="li">计划时间段<text>{{taskInfoList[0]?.planStartDate+' 至 '+taskInfoList[0]?.planEndDate}}</text>
			</view>
		</view>
		<view class="title">进度填报</view>
		<tui-form ref="formRef" :show-message="false" :model="formData">
			<tui-form-item labelWidth='180' asterisk label="累计完成量" prop="addUp">
				<tui-input v-model="formData.addUp" padding="0" :borderBottom="false" placeholder="请输入"></tui-input>
			</tui-form-item>
			<tui-form-item labelWidth='180' asterisk label="当前进度" prop="progress">
				<tui-input v-model="formData.progress" padding="0" :borderBottom="false" placeholder="请输入"></tui-input>
			</tui-form-item>
			<tui-form-item labelWidth='180' asterisk label="本次完成量" prop="finishQuantity">
				<tui-input v-model="formData.finishQuantity" padding="0" :borderBottom="false" placeholder="请输入"></tui-input>
			</tui-form-item>
			<tui-form-item labelWidth='180' asterisk label="存在问题" prop="problem">
				<tui-input v-model="formData.problem" padding="0" :borderBottom="false" placeholder="请输入"></tui-input>
			</tui-form-item>
			<tui-form-item labelWidth='180' asterisk label="备注" prop="memo">
				<tui-input v-model="formData.memo" padding="0" :borderBottom="false" placeholder="请输入"></tui-input>
			</tui-form-item>
			<tui-form-button text="提交" @click="submit"></tui-form-button>
		</tui-form>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		getTaskInfo,
		addProgress
	} from '@/apis/projectPlan.js'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const taskInfoList = ref([])
	const planId = ref(0)
	const rules = [{
		name: "addUp",
		rule: ["required"],
		msg: ["请输入"]
	}, {
		name: "progress",
		rule: ["required"],
		msg: ["请输入"]
	}, {
		name: "finishQuantity",
		rule: ["required"],
		msg: ["请输入"]
	}, {
		name: "problem",
		rule: ["required"],
		msg: ["请输入"]
	}, {
		name: "memo",
		rule: ["required"],
		msg: ["请输入"]
	}];
	const formRef = ref(null);
	const formData = ref({
		addUp: "",
		progress: "",
		finishQuantity: "",
		problem: "",
		memo: "",
	})


	onLoad(({
		projectPlanId
	}) => {
		planId.value = projectPlanId
		getTaskInfo(projectPlanId).then(res => {
			formData.value.progress = res.data.data.progress
			formData.value.addUp = res.data.data.addUp
			taskInfoList.value.push(res.data.data)
		})
	})

	const submit = (values) => {
		if (formRef.value) {
			formRef.value.validate(formData.value, rules, true).then(res => {
				if (res.isPass) {
					addProgress(planId.value,formData.value).then(res => {
						if (res.data.code === 200) {
							uni.navigateBack()
							plus.nativeUI.toast("提交成功");
						}
					})
				}
			})
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background-color: #fafafa;
		padding: 0 10px 10px 10px;

		.title {
			padding: 15px 0;
			font-size: 17px;
			color: #333333;
			font-weight: bold;
		}

		.msg {
			display: flex;
			color: #323233;
			background-color: white;
			flex-direction: column;

			.li {
				flex: 1;
				justify-content: center;
				align-items: center;
				margin: 10px 0px 10px 15px;

				text {
					margin-left: 15px;
				}
			}
		}
	}
</style>